package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import java.sql.BatchUpdateException;

public class MainActivity extends AppCompatActivity {

    private Button mBtnGv;
    private Button mBtnLv;
    private Button mBtnAGv;
    private Button mBtnBLv;
    private Button mBtn_recyclerview;
    private Button mBtn_HttpUrl;
    private Button mBtn_HttpOk;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        initView();
        setListeners();
    }

    private void setListeners() {
        OnClick onClick = new OnClick();
        mBtnGv.setOnClickListener(onClick);
        mBtnLv.setOnClickListener(onClick);
        mBtnAGv.setOnClickListener(onClick);
        mBtnBLv.setOnClickListener(onClick);
        mBtn_recyclerview.setOnClickListener(onClick);
        mBtn_HttpUrl.setOnClickListener(onClick);
        mBtn_HttpOk.setOnClickListener(onClick);
    }

    public class  OnClick implements View.OnClickListener{
        @Override
        public void onClick(View v) {
           Intent intent = null;
            switch (v.getId()){
                case R.id.btn_gv:
                    intent = new Intent(getApplicationContext(),GridViewDemoActivity.class);
                    break;
                case R.id.btn_lv:
                    intent = new Intent(MainActivity.this,ListViewActivity.class);
                    break;
                case R.id.btn_arrayListView:
                    intent = new Intent(getApplicationContext(),FruitListViewActivity.class);
                    break;
                case R.id.btn_baseListview:
                    intent = new Intent(getApplicationContext(),BaseAdapterActivity.class);
                    break;
                case R.id.btn_rv:
                    intent = new Intent(getApplicationContext(), RecyclerViewActivity.class);
                    break;
                case R.id.btn_httpUrl:
                    intent = new Intent(getApplicationContext(),HttpUrlconnectActivity.class);
                    break;
                case R.id.btn_OkHttp:
                    intent = new Intent(getApplicationContext(),OkHttpActivity.class);
                    break;
                default:
                    break;
            }
            startActivity(intent);
        }
    }

    private void initView() {
        mBtnGv= findViewById(R.id.btn_gv);
        mBtnLv= findViewById(R.id.btn_lv);
        mBtnAGv = findViewById(R.id.btn_arrayListView);
        mBtnBLv = findViewById(R.id.btn_baseListview);
        mBtn_recyclerview = findViewById(R.id.btn_rv);
        mBtn_HttpUrl = findViewById(R.id.btn_httpUrl);
        mBtn_HttpOk = findViewById(R.id.btn_OkHttp);
    }
}